package hn.cch.advanced.concurrent.locks;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ThreadDemo {

    private final static Logger logger = LoggerFactory.getLogger(ThreadDemo.class);

    public static void main(String[] args) {
        logger.debug("start");
        Thread thread = new Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()) { // 是否被中断了
                    logger.debug("interrupted");
                    break;
                }
                logger.debug("running");
            }

        }, "thread");
        thread.start();
        try {
            Thread.sleep(1000);
            logger.debug("sleep");
        } catch (InterruptedException e) {
            logger.error("InterruptedException:", e);
        }

        thread.interrupt();// 中断线程
        logger.debug("stop");
    }

}
